﻿using System;
using System.Collections.Generic;
using System.IO;
using InTheHand.Net;
using InTheHand.Net.Sockets;

namespace ConnectionManager.BlueToothConnection.PS3
{
    public class PS3BTConnectionManager : IConnectionManager
    {
        private int CTRL = 17;
        private int DATA = 19;
        private string PS3Adress = "";
        private Guid guid = new Guid("{7A51FDC2-FDDF-4c9b-AFFC-98BCD91BF93B}");
        
        private Stream _dataBtStream;
        private Stream _ctrlBtStream;

        public bool Connect()
        {
            throw new System.NotImplementedException();
        }

        public bool Disconnect()
        {
            throw new System.NotImplementedException();
        }

        public void SendData()
        {
            throw new System.NotImplementedException();
        }

        public List<string> GetSerialPorts()
        {
            byte[] buf = new byte[1024];

            var adress = BluetoothAddress.Parse(PS3Adress);
            BluetoothEndPoint endPoint = new BluetoothEndPoint(adress, guid ,CTRL);   
            
            L2CapListener listener = new L2CapListener(endPoint);
            L2CapClient client = new L2CapClient();
            
            client.Connect(endPoint);
            var listenz = listener.AcceptClient();
            
            _ctrlBtStream = client.GetStream();
            _ctrlBtStream.Write(buf,0,1024);

            return null;
        }

        public void StopDataSend()
        {
            throw new System.NotImplementedException();
        }

        public bool IsConnected()
        {
            throw new System.NotImplementedException();
        }

        struct MyStruct
        {
            // Do initialized structs :D
            //{"res",12,"ada"},
            //{}
        };
    }
}